package com.manage.modules.controller;

import cn.hutool.core.bean.BeanUtil;
import com.manage.modules.bo.PostSurfMinAddBo;
import com.manage.modules.bo.TBaseStationInfoAddBo;
import com.manage.modules.bo.TBaseSurfMinAddBo;
import com.manage.modules.domain.TBaseDataRecord;
import com.manage.modules.domain.TBaseDataTransfer;
import com.manage.modules.domain.TBaseStationStateYun;
import com.manage.modules.domain.TBaseSurfMin;
import com.manage.modules.scoket.MySocketServer;
import com.manage.modules.scoket.SocketSendMessageVo;
import com.manage.modules.service.*;
import com.manage.modules.vo.TBaseSurfMinVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 数据传输控制层
 *
 * @author xu
 * 2021/8/11 10:16
 */
@RestController
@RequestMapping("/serverData")
public class ServerDataPostController {
    @Resource
    private ITBaseStationInfoService stationInfoService;
    @Resource
    private ITBaseSurfMinService surfMinService;
    @Resource
    private ITBaseStationStateYunService stationStateYunService;
    @Resource
    private MySocketServer mySocketServer;
    @Resource
    private ITBaseDataRecordService dataRecordService;
    @Resource
    private ITBaseDataTransferService dataTransferService;


    @PostMapping("/postDataTransfer")
    public void postDataTransfer(@RequestBody List<TBaseDataTransfer> dataTransferList) {
        dataTransferService.updateOrSave(dataTransferList);
    }

    @PostMapping("/postDataRecord")
    public void postDataRecord(@RequestBody TBaseDataRecord dataRecord) {
        dataRecordService.saveOrUpdate(dataRecord);
    }

    @PostMapping("/postStation")
    public void postStation(@RequestBody List<TBaseStationInfoAddBo> stationInfoAddBoList) {
        stationInfoService.saveListStation(stationInfoAddBoList);
    }

    @PostMapping("/postOverSurfMin")
    public void postOverSurfMin(@RequestBody List<TBaseSurfMin> surfMinList) {
        surfMinService.postOverSurfMin(surfMinList);
        SocketSendMessageVo sendMessageVo = new SocketSendMessageVo();
        sendMessageVo.setType("3");
        sendMessageVo.setMessage("要素有修改");
        // 通知前端
        mySocketServer.groupMessage(sendMessageVo);
    }

    @PostMapping("/postSurfMin")
    public void postSurfMin(@RequestBody List<TBaseSurfMin> surfMinList) {
        surfMinService.saveBatch(surfMinList);
        SocketSendMessageVo sendMessageVo = new SocketSendMessageVo();
        sendMessageVo.setType("3");
        sendMessageVo.setMessage("来新要素了");
        // 通知前端
        mySocketServer.groupMessage(sendMessageVo);
    }


    @PostMapping("/postStationState")
    public void postStationState(@RequestBody List<TBaseStationStateYun> stateYunList) {
        stationStateYunService.saveBatch(stateYunList);
        SocketSendMessageVo sendMessageVo = new SocketSendMessageVo();
        sendMessageVo.setType("2");
        sendMessageVo.setMessage("来新状态了");
        // 通知前端
        mySocketServer.groupMessage(sendMessageVo);
    }

    @PostMapping("/postOverStationState")
    public void postOverStationState(@RequestBody List<TBaseStationStateYun> stateYunList) {
        stationStateYunService.postOverStationState(stateYunList);
        SocketSendMessageVo sendMessageVo = new SocketSendMessageVo();
        sendMessageVo.setType("2");
        sendMessageVo.setMessage("状态来修改了");
        // 通知前端
        mySocketServer.groupMessage(sendMessageVo);
    }
}
